﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using QLTV.Public;
using System.Data.SqlClient;

namespace QLTV.DAL
{
    public class LoaiDGDAL
    {
        ConnectionData connect;
        public DataTable LoaiDG_LoadDuLieuCotMaLDG(LoaiDGDTO ldgDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@maldg";
                value[0] = ldgDTO.MaLDG;
                return connect.GetData("LoaiDocGia_LoadDuLieuCotMaLDG", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public int nhapLDG(LoaiDGDTO ldgDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 2;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@maldg";
                value[0] = ldgDTO.MaLDG;
                name[1] = "@tenldg";
                value[1] = ldgDTO.TenLDG;

                return connect.UpdateData("loaiDocGia_InsertUpdate", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable LoaiDG_LoadDuLieu()
        {
            try
            {
                connect = new ConnectionData();
                return connect.GetData("[LoaiDG_LoadDuLieu]");
            }
            catch (SqlException ex)
            {
                throw ex;

            }
        }
        public int LoaiDocGia_Xoa(LoaiDGDTO dgDTO) {
            try {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name=new string[Nparamater];
                object[] values=new object[Nparamater];
                name[0] = "@MaLDG";
                values[0] = dgDTO.MaLDG;
                return connect.UpdateData("LoaiDocGia_Xoa",name,values,Nparamater);

            }catch(SqlException ex){
                throw ex;
            }
        }
        public DataTable LoadTenLoaiDG() {
            try
            {
                connect = new ConnectionData();
                return connect.GetData("LoadTenLoaiDG");
            }
            catch(SqlException ex) {
                throw ex;
            }
        }
    }
}
